package com.missilike.api.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.missilike.biz.IMilAdvertService;
import com.missilike.core.result.CommonResult;
import com.missilike.core.utils.ResultUtils;
import com.missilike.domain.response.MilAdvertInfo;
import com.missilike.repository.entity.MilAdvert;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: starmile
 * @Description:
 * @Create: 2019-01-03 23:46
 **/
@Slf4j
@RestController
@RequestMapping("/api/advert")
public class AdvertController {
    private final IMilAdvertService milAdvertService;
    @Autowired
    public AdvertController(IMilAdvertService milAdvertService){
        this.milAdvertService = milAdvertService;
    }

    @ApiOperation(value = "getNew", notes = "获取最新的广告信息")
    @RequestMapping(value = "/getNew", method = {RequestMethod.GET}, produces = "application/json")
    @ResponseBody
    public CommonResult getNew(){
        MilAdvertInfo milAdvertInfo = milAdvertService.getNew();
        return ResultUtils.ok(milAdvertInfo);
    }

    @ApiOperation(value = "getList", notes = "获取最新的广告列表")
    @RequestMapping(value = "/getList", method = {RequestMethod.GET}, produces = "application/json")
    @ResponseBody
    public CommonResult getList(@RequestParam(value = "pageNum", required = false, defaultValue = "1") int pageNum,
                                @RequestParam(value = "pageSize", required = false, defaultValue = "20") int pageSize){
        List<MilAdvertInfo> milAdvertInfos = milAdvertService.getList(pageNum, pageSize);
        return ResultUtils.ok(milAdvertInfos);
    }
}
